﻿$(document).ready(function () {
    
});

function ValidateForm() {
    var sEmail = $.trim($("input[id$='txtEmail']").val());
    var sPhone = $.trim($("input[id$='txtPhone']").val());
    var sMess = $.trim($("textarea[id$='txtMessage']").val());
    $("#spEmailError").text("");
    $("#spPhoneError").text("");
    $("#spMessError").text("");
    if (sEmail.length > 0) {
        if (ValidateEmail(sEmail) == false) {
            $("#spEmailError").text("Email is not valid.");
            return false;
        }
    }
    if (sPhone.length <= 0) {
        $("#spPhoneError").text("You must enter your phone number.");
        return false;
    }
    if (ValidatePhone(sPhone) == false)  {
        $("#spPhoneError").text("Phone number is not valid.");
        return false;
    }
  
    if (sMess.length < 10) {
        $("span[id$='spMessError']").text("You must enter your request and length of message between 10 and 500 characters.");
        return false;
    }
    return true;
}

function ValidateEmail(sEmail) {
    var RE_EMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (RE_EMail.test(sEmail))
        return true;
    return false;
}

function ValidatePhone(sPhone) {
    var RE_NUM = /^([0-9]{5,20})$/;
    return RE_NUM.test(sPhone);
}